Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mastodon comments feature. Fixes #157 #158

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ClemABT
Copy link

@ClemABT ClemABT commented Mar 21, 2024

It is needed to add params at top of an article to enable comments feature.

Example:

[comments]
  host = "mastodon.social"
  username = "fabi1cazenave"
  id = 112124416010685631

Copy link
Collaborator

@fabi1cazenave fabi1cazenave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing ! Silly question, have you experimented it yet ?

* ╰───────────────────────────────────────────────────────────────╯
**/

section#comments #comments-wrapper {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicks, mostly for consistency :

  • #comments-wrapper is enough here
  • empty lines between CSS rules please (much easier to navigate with Vim)
  • space after the colon sign please (: rather than :)

margin:1.5em 0;
padding:0 var(25px);
}
section#comments .comment {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.comment is enough here and in all following rules

</div>
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript>
<script src="/js/purify.min.js"></script>
<script type="text/javascript">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind putting this script in a separate file, e.g. comments.js or mastodon-comments.js please ?

* ╭───────────────────────────────────────────────────────────────╮
* │ Comments │
* ╰───────────────────────────────────────────────────────────────╯
**/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be in a separate CSS file, e.g. comments.css, as it’s only used by single-page articles.

@ClemABT
Copy link
Author

ClemABT commented Mar 22, 2024

Yes, I have tested it on the existing article with the provided conf sample:
image

I will update the PR with your comments

Copy link
Owner

@Nuclear-Squid Nuclear-Squid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that’s pretty good ! It seems to be working really well on my end, the render could be a bit fancier, especially with heavily nested responses, but we’ll address that later, it’s good enough as is.

I do have a few problems with the overall code structure, though. The main one being the huge js script in the middle of layouts/partials/comments.

</noscript>
</div>
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript>
<script type="text/javascript">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the code to fetch the comments to a separate layout partial is a step in the right direction, but I would greatly prefer if this was in it’s own js file in ergol/code/comments.js.

You can use Hugo’s js.Build with a params dict to pass in values from the front matter to the js script.

Copy link
Author

@ClemABT ClemABT Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to pass Hugo variables to a separate js file, thanks for the tip, I will have a look

href="https://{{ .host }}/@{{ .username }}/{{ .id }}">le post original</a> sur Mastodon.</p>
</noscript>
</div>
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This noscript tag is redundant, the one above is more detailed

Comment on lines 81 to 85
if (
descendants &&
Array.isArray(descendants) &&
descendants.length > 0
) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be an early return, with a few error messages in case it gets triggered, depending on the context (like no comments yet, fetch failed…)

) {
commentsWrapper.innerHTML = "";

descendants.forEach(function (status) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is quite a bit of code needed to properly render a comment, so it could be nice to make it a web component. If it requires too much work on your end, we can leave this as is and I’ll come back to it later, it’s not that big a deal.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to do it properly, so I will leave it to you if you don't mind.

@ClemABT
Copy link
Author

ClemABT commented Apr 2, 2024

New commits to separate js code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants